import { Request, Response } from "express";
import { OperationalService } from "../../services/operational.service";
enum StatusCode {
    ENABLED = 1,
    UNENABLED = 0,
}
export class Controller {
    // 获取运营位接口
    static get(req: Request, resp: Response): void {
        let status = Number(req.query.status as string);
        if (!status) {
            status = 0;
        }
        OperationalService.getOperational(status).then((data) => {
            resp.status(200).json({ msg: 'ok', datas: data });
        }).catch((error) => {
            resp.status(200).json({ msg: 'error', error });
        })
    }
    // 新增运营位接口
    static add(req: Request, resp: Response): void {
        // 解析请求参数
        let name = req.body.name;
        let status = req.body.status;
        let cover = req.body.cover;
        let content = req.body.content;
        let uri = req.body.uri;
        OperationalService.addOperational({ name, status, cover, content, uri }).then(() => {
            resp.status(200).json({ msg: 'ok' });
        }).catch((error) => {
            resp.status(200).json({ msg: 'error', error });
        });
    }
    // 更新运营位状态接口
    static update(req: Request, resp: Response): void {
        let status = req.body.status;
        let id = req.body.id;
        if (![StatusCode.ENABLED, StatusCode.UNENABLED].includes(status)) {
            status = StatusCode.UNENABLED
        }
    }
}